import toolAction from "@/tool/http/tool-action";
import { defineStore } from "pinia";

export const useAreaStore = defineStore("area", {
  state: () => {
    return {
      areas: JSON.parse(localStorage.getItem("com-area") || "[]"),
    };
  },
  actions: {
    async listArea() {
      if (this.areas && this.areas.length > 0) {
        return this.areas;
      }
      let res = await toolAction.run(
        "action-area-list",
        "63705362eaed4cafa7fa798403b18272"
      );
      localStorage.setItem("com-area", JSON.stringify((this.areas = [res])));
      return [res];
    },
  },
});
